package com.woniu.dao.impl;

import com.woniu.dao.StudentDao;
import com.woniu.entity.Student;

import java.lang.reflect.Field;
import java.sql.*;
import java.util.Scanner;

public class StudentDaoImpl implements StudentDao {

    @Override
    public void insertStudent(Student student) throws Exception{
        Connection connection = JdbcUnit.connection();
        String sql="insert into student values(?,?,?,?)";
        JdbcUnit.xxx(connection, sql, student.getId(), student.getName(), student.getAge(), student.getPassword());
    }

    @Override
    public void updateStudent(Student student)throws Exception {
        Connection connection = JdbcUnit.connection();
        String sql="update student set name=?,age=?,password=? where id=?";
        JdbcUnit.xxx(connection, sql,student.getName(), student.getAge(), student.getPassword(),student.getId());
    }

    @Override
    public void deleteStudent(int num)throws Exception {
        Connection connection = JdbcUnit.connection();
        String sql="delete from student where id=?";
        JdbcUnit.xxx(connection, sql,num);
    }


    @Override
    public void selectStudent(String name,String pwd) throws Exception {
        Connection connection = JdbcUnit.connection();
        String sql="select * from student where name=? and password=?";
        Class<?> clazz = Class.forName("com.woniu.entity.Student");
        JdbcUnit.ttt(connection,sql,clazz,name,pwd);
    }

}
